% 构造三个符合高斯分布的点集并合并
PntSet1=mvnrnd([2 3],[1 0;0 2],500);
PntSet2=mvnrnd([6 7],[1 0;0 2],500);
PntSet3=mvnrnd([14 9],[1 0;0 1],500);
PntSet=[PntSet1;PntSet2;PntSet3];

% 构造GMM模型
tic
[Mu,Sigma,Pi,Class]=gaussKMeans(PntSet,3,'dis');
toc

% -------------------------------------------------------------------------
% 构造概率密度函数
func=getGaussFunc(Mu,Sigma,Pi);

% 绘制概率密度图像
figure('Units','normalized','Position',[.3,.2,.6,.65])
[X1,X2]=meshgrid(0:.4:16,0:.4:12);
surf(X1,X2,func(X1,X2),'LineWidth',1)
%修饰一下
ax=gca;hold(ax,'on');
ax.XLim=[0,16];
ax.YLim=[0,12];
ax.LineWidth=2;
ax.Box='on';
ax.TickDir='in';
ax.XMinorTick='on';
ax.YMinorTick='on';
ax.ZMinorTick='on';
ax.XColor=[.3,.3,.3];
ax.YColor=[.3,.3,.3];
ax.ZColor=[.3,.3,.3];
ax.FontWeight='bold';
ax.FontName='Cambria';
ax.FontSize=13;
ax.GridLineStyle='--';

% -------------------------------------------------------------------------
% 绘制散点图
figure('Units','normalized','Position',[.3,.2,.5,.65])
ax=gca;hold(ax,'on');
colorList=[0.4  0.76 0.65
           0.99 0.55 0.38 
           0.55 0.63 0.80];
for i=1:3
    scatter(PntSet(Class==i,1),PntSet(Class==i,2),180,'filled',...
        'LineWidth',2.2,'MarkerEdgeColor',[1 1 1]*.3,'MarkerFaceColor',colorList(i,:));
end
% 绘制置信椭圆       
for i=1:3
    [X,Y]=getEllipse(Mu(i,:),Sigma(:,:,i),9.21,100);
    fill(X,Y,colorList(i,:),'EdgeColor',colorList(i,:).*.5,...
        'LineWidth',3,'FaceAlpha',.2)
    
end     
legend('pointSet1','pointSet2','pointSet3','conf.ellipse1','conf.ellipse2','conf.ellipse3')
%修饰一下
ax.XLim=[-2,18];
ax.YLim=[-2,14];
ax.LineWidth=2;
ax.Box='on';
ax.TickDir='in';
ax.XMinorTick='on';
ax.YMinorTick='on';
ax.XGrid='on';
ax.YGrid='on';
ax.GridLineStyle='--';
ax.XColor=[.3,.3,.3];
ax.YColor=[.3,.3,.3];
ax.FontWeight='bold';
ax.FontName='Cambria';
ax.FontSize=15;
%ax.Color=[0.9,0.9,0.9];


